import {computed} from 'vue'
import { useStore } from 'vuex'

export function useMapper(mapper,mapFn){
    // 拿到store对象
    const store = useStore()

    // 获取到相应的对象的functions:{name:function,age:function}
    const storeMapperFns = mapFn(mapper)

    // 对数据进行转换
    const storeMapper = {}
    Object.keys(storeMapperFns).forEach(fnKey=>{
        const fn = storeMapperFns[fnKey].bind({$store:store})
        storeMapper[fnKey] = computed(fn)
    })
    
    return storeMapper
}